# encoding: utf-8
""" 
@version: v1.0 
@author: autumner 
@license: Apache Licence  
@contact: 18322313385@163.com 
@site:  
@software: PyCharm 
@file: class_parent.py 
@time: 2019/6/13 10:12
"""

'''
调用父类或类继承
'''


class A:
    def __init__(self):
        self.x = 0


class B:
    def __init__(self):
        super.__init__()
        self.y = 1

# print('\n'.join(['%s:%s' % item for item in object.__dict__.items()]))


'''
子类中扩展property
'''

class Person:
    def __init__(self, name):
        self.name = name

    # Getter function
    @property
    def name(self):
        return self._name

    # Setter function
    @name.setter
    def name(self, value):
        if not isinstance(value, str):
            raise TypeError('Expected a string')
        self._name = value

    # Deleter function
    @name.deleter
    def name(self):
        raise AttributeError("Can't delete attribute")


class SubPerson(Person):
    @property
    def name(self):
        print('Getting name')
        return super().name

    @name.setter
    def name(self, value):
        print('Setting name to ', value)
        super(SubPerson, SubPerson).name.__set__(self, value)

    @name.deleter
    def name(self):
        print('Deleting name')
        super(SubPerson, SubPerson).name.__delete__(self)

print('\n'.join(['%s:%s' % item for item in SubPerson.__dict__.items()]))
s = SubPerson('tom')
print(s.name)
